<!--
 * @Description: 
 * @Author: ljl
 * @Date: 2025-04-25 10:02:38
 * @LastEditors: rendc
 * @LastEditTime: 2025-05-21 15:11:01
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            width: 600px;
            margin: 0 auto;
            text-align: center;
        }

        caption {
            font-size: 18px;
            margin-bottom: 10px;
            font-weight: 400;
        }

        th {
            background: rgb(240, 239, 242);
        }

        tr {
            height: 40px;
            cursor: pointer;
        }

        table,
        th,
        td {
            border: 1px solid #ccc;
            border-collapse: collapse;
        }

        tr:hover {
            background: #eee;
        }
    </style>
</head>

<body>
    <h3>学生列表</h3>
    <p>将数据渲染到页面中</p>
    <!-- <tr>
        <th>序号</th>
        <th>姓名</th>
        <th>年龄</th>
        <th>性别</th>
        <th>家乡</th>
    </tr>
    <tr>
        <td>1</td>
        <td>小明</td>
        <td>18</td>
        <td>男</td>
        <td>河北</td>
    </tr>
    <tr>
        <td>2</td>
        <td>小王</td>
        <td>19</td>
        <td>女</td>
        <td>北京</td>
    </tr>
    <tr>
        <td>3</td>
        <td>小李</td>
        <td>17</td>
        <td>男</td>
        <td>上海</td>
    </tr>
    <tr>
        <td>4</td>
        <td>小赵</td>
        <td>20</td>
        <td>男</td>
        <td>广东</td>
    </tr> -->
    <table>
        <caption>学生列表</caption>
        <tr>
            <th>序号</th>
            <th>姓名</th>
            <th>年龄</th>
            <th>性别</th>
            <th>家乡</th>
        </tr>
    <script>
        // 1.数据
        let students = [
            { name: '小明', age: 18, sex: '男', home: '河北' },
            { name: '小王', age: 19, sex: '女', home: '北京' },
            { name: '小李', age: 17, sex: '男', home: '上海' },
            { name: '小赵', age: 20, sex: '男', home: '广东' }
        ]
        // 2.渲染页面
        for (let i = 0; i < students.length; i++) {
            document.write(`
            <tr>
                <td>${i + 1}</td>
                <td>${students[i].name}</td>
                <td>${students[i].age}</td>
                <td>${students[i].sex}</td>
                <td>${students[i].home}</td>
            </tr>
            `)
        }
    </script>

    </table>

</body>

</html>